<template>
	<view>
		<u-navbar title="我的" :titleStyle="{color: '#fff'}" placeholder leftIconSize="0" :bgColor="appColor"/>
		<scroll-view :scroll-y="true" :style="{height: scrollViewHeight, backgroundColor: '#f5f5f5'}">
			<template v-if="loading">
				<view style="padding: 32rpx;">
					<u-skeleton style="margin-bottom: 32rpx;" :loading="loading" avatar rows="7" v-for="i in 4" :key="i"></u-skeleton>
				</view>
			</template>
			<template v-else>
				<!-- 头部 -->
				<view class="me-header" :style="{backgroundColor: appColor}">
					<view style="height: 32rpx;"></view>
					<view class="me-profile">
						<u--image mode="aspectFill" shape="circle" :src="userInfo.avatar" width="100rpx" height="100rpx"></u--image>
						<view class="me-profile-center">
							<view>{{userInfo.username}}</view>
							<view>{{userInfo.phone}}</view>
						</view>
						<u-icon @click="toPage({url: '/pageDiamond1/me/setting'})" name="setting-fill" color="#fff" size="28"></u-icon>
					</view>
					<view class="me-moeny">
						<view class="me-moeny-item" @click="toCharge({url: '/pageDiamond1/me/recharge'})">
							<view class="me-moeny-item-icon">
								<text class="iconfont icon-yue" style="font-weight: bold;color: #fff; size: 32rpx"></text>
								<text style="padding-left: 4rpx;"> 余额</text>
							</view>
							<text class="me-moeny-item-num">&yen;{{userInfo.balance | moneyFormat}}</text>
						</view>
						<view style="width: 32rpx;"/>
						<!-- <view class="me-moeny-item">
							<view class="me-moeny-item-icon">
								<text class="iconfont icon-zijin_dongjie_o" style="font-weight: bold; color: #fff; size: 32rpx"></text>
								<text style="padding-left: 4rpx;"> 冻结</text>
							</view>
							<text class="me-moeny-item-num">&yen;{{userInfo.balance}}</text>
						</view> -->
						<view style="width: 32rpx;"/>
						<view class="me-moeny-item" @click="toPage({url: '/pages/me/points'})">
							<view class="me-moeny-item-icon">
								<text class="iconfont icon-jifen" style="color: #fff; size: 32rpx"></text>
								<text style="padding-left: 4rpx;"> 积分</text>
							</view>
							<text class="me-moeny-item-num">{{userInfo.score}}</text>
						</view>
					</view>
					<view class="me-header-vip">
						<u-icon name="integral" color="#000" size="32"></u-icon>
						<text class="me-header-vip-1">{{userInfo.memberLevel}}</text>
						<view class="me-header-vip-text">会员升级, 享受超级权益</view>
					</view>
				</view>
				<!-- 内容 -->
				<view style="height: 64rpx;"/>
				<view class="me-content">
					<view class="me-content-item" style="display: flex;align-items: center;justify-content: space-between;">
						<view class="me-content-item1" @click="toPage({url: '/pages/me/ticketOrder'})">
							<text style="color: #333;" class="iconfont icon-jingqu"></text>
							<view style="height: 8rpx;"/>
							<text class="text">门票订单</text>
						</view>
						<view class="me-content-item1" @click="toPage({url: '/pages/me/shopOrder'})">
							<text style="color: #333;" class="iconfont icon-shangcheng2"></text>
							<view style="height: 8rpx;"/>
							<text class="text">商城订单</text>
						</view>
						<view class="me-content-item1" @click="toPage({url: '/pages/me/fosterOrder'})">
							<text style="color: #333;" class="iconfont icon-huapen"></text>
							<view style="height: 8rpx;"/>
							<text class="text">认养订单</text>
						</view>
						<view class="me-content-item1" @click="show = true">
							<text style="color: #333;" class="iconfont icon-kefufill"></text>
							<view style="height: 8rpx;"/>
							<text class="text">售后订单</text>
						</view>
					</view>
					<view class="me-content-item">
						<view class="me-content-item-content-box">
							<view @click="toPage(tag)" class="me-content-item-content" v-for="(tag, index) in fzList" :key="index">
								<text :class="['iconfont', tag.icon]" style="color: #333; font-size: 48rpx"></text>
								<text style="font-weight: bold;padding-top: 4rpx;font-size: 32rpx;">{{tag.title}}</text>
							</view>
						</view>
					</view>
					<view class="me-content-item" v-if="userInfo.isManagement">
						<view class="me-content-item-content-box">
							<view @click="toPage(tag)" class="me-content-item-content" v-for="(tag, index) in sjList" :key="index">
								<template v-if="!tag.noShow">
									<text :class="['iconfont', tag.icon]" style="color: #333; font-size: 48rpx"></text>
									<text style="font-weight: bold;padding-top: 4rpx;font-size: 32rpx;">{{tag.title}}</text>
								</template>
								<template v-else>
									<text :class="['iconfont', tag.icon]" style="color: #fff!important; font-size: 48rpx"></text>
									<text style="font-weight: bold;padding-top: 4rpx;font-size: 32rpx;color: #fff!important;">{{tag.title}}</text>
								</template>
							</view>
						</view>
					</view>
				</view>
			</template>
		</scroll-view>
		<u-action-sheet @close="show = false" cancelText="取消" :closeOnClickAction="true" :closeOnClickOverlay="true" @select="selectClick" :actions="list" :show="show"></u-action-sheet>
	</view>
</template>

<script>
	import {mapState, mapActions} from 'vuex';
	import {queryAccountById} from '@/api/me.js'
	import {getToken} from '@/utils/auth.js';
	export default {
		data() {
			return {
				show: false,
				loading: true,
				// 辅助icon
				fzList: [
					{title: '收货地址', icon: 'icon-shouhuodizhi', url: '/pages/me/address'},
					// {title: '专属客服', icon: 'icon-kefufill', url: ''},
					{title: '优惠券', icon: 'icon-youhuiquan', url: '/pages/me/myCoupon'},
					{title: '去领券', icon: 'icon-quan', url: '/pages/me/coupon'},
					// {title: '签到', icon: 'chat-fill', url: ''},
					{title: '常见问题', icon: 'icon-changjianwentixiangguanwenti2', url: '/pages/me/question'},
				],
				sjList: [
					{title: '农事工单', icon: 'icon-jilu2', url: '/pageDiamond1/routingInspection/index'},
					{title: '巡地记录', icon: 'icon-gongdan1', url: '/pageDiamond1/routingInspection/record'},
					// {title: '认养工单', icon: 'icon-jilumian', url: '/pages/me/plan'},
					{title: '巡地记录', icon: 'icon-gongdan1', url: '/pages/me/plan', noShow: true},
					{title: '巡地记录', icon: 'icon-gongdan1', url: '/pages/me/plan', noShow: true},
				],
				list: [
					{
						name: '门票订单',
					},
					{
						name: '商城订单',
					},
					{
						name: '认养订单',
					},
				],
			}
		},
		computed: {
			...mapState(['userInfo', 'appInfo']),
			scrollViewHeight() {
				return this.scrollHeight - 50 - 1 - 44 + 'px';
			},
			appColor() {
				return this.appPrimaryColor
			},
		},
		created() {
			this.loading = true;
			// 更新用户信息
			queryAccountById({id: this.userInfo.id}).then(res => {
				this.setUserInfo({
					userInfo: res.result,
					token: getToken()
				})
			}).finally(() => {
				this.loading = false;
			})
		},
		methods: {
			...mapActions(['setUserInfo']),
			selectClick({name}) {
				this.show = false;
				if(name === '商城订单') {
					this.$cuNavigateTo('/pages/me/afterSale');
				} else if(name === '认养订单') {
					this.$cuNavigateTo('/pages/me/afterSaleFoster');
				} else if(name === '门票订单') {
					this.$cuNavigateTo('/pages/me/afterSaleTicket');
				}
			},
			toPage({url, redirectTo, noShow}) {
				if(!url || noShow) return
				this.$cuNavigateTo(url);
			},
			// 充值
			toCharge({url}) {
				const {rechargeIsOpen} = this.appInfo;
				console.log(this.appInfo);
				if(rechargeIsOpen === '0') {
					return this.$cuTip('充值关闭');
				}
				this.toPage({url});
			}
		}
	}
</script>


<style lang="scss" scoped>
	.me-content {
		padding: 0 32rpx;
		.me-content-item {
			padding: 32rpx;
			background-color: #fff;
			border-radius: 16rpx;
			margin-bottom: 32rpx;
			.me-content-item1 {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				.iconfont {
					font-size: 48rpx;
				}
				.text {
					font-size: 32rpx;
					color: #333;
					font-weight: bold;
				}
			}
			
			.me-content-item-title {
				display: flex;
				align-items: center;
				justify-content: space-between;
				.me-content-item-text {
					font-size: 32rpx;
					color: #333;
					font-weight: bold;
				}
				.me-content-item-right {
					font-size: 24rpx;
					color: #666;
					display: flex;
					align-items: center;
				}
			}
			.me-content-item-content-image {
				display: flex;
				align-items: center;
				height: 156rpx;
				padding-top: 32rpx;
				.me-content-item-content-image-r {
					padding-left: 16rpx;
					height: 100%;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					font-size: 26rpx;
					color: #666;
					.r-tag {
						font-size: 28rpx;
						padding: 0 12rpx;
						margin-left: 32rpx;
						border-radius: 8rpx;
						border-width: 2rpx;
						border-style: solid;
					}
					.r-1 {
						color: #333;
						padding-left: 16rpx;
					}
				}
			}
			.me-content-item-content-box {
				display: flex;
				align-items: center;
				justify-content: space-between;
				.me-content-item-content {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					color: #333;
					position: relative;
					color: #333;
				}
			}
			
			.me-content-item-content-box1 {
				flex-wrap: wrap;
				justify-content: flex-start;
				padding-top: 0;
				.me-content-item-content {
					width: 25%;
					padding-top: 32rpx;
				}
			}
		}
	}
	
	.me-header {
		padding: 0 32rpx;
		height: 400rpx;
		.me-profile {
			display: flex;
			align-items: center;
			justify-content: space-between;
			.me-profile-center {
				flex: 1;
				padding-left: 16rpx;
				color: #fff;
				font-size: 28rpx;
				font-weight: bold;
			}
		}
		.me-moeny {
			display: flex;
			color: #fff;
			padding: 32rpx 0;
			.me-moeny-item {
				padding: 16px 0;
				background-color: rgba(255, 255, 255, 0.2);
				border-radius: 16rpx;
				flex: 1;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				font-size: 28rpx;
				.me-moeny-item-icon {
					display: flex;
					align-items: center;
				}
				.me-moeny-item-num {
					font-size: 32rpx;
				}
			}
		}
		.me-header-vip {
			height: 96rpx;
			background-color: rgba(245, 214, 156, 1);
			border-radius: 16rpx;
			display: flex;
			align-items: center;
			padding: 0 64rpx;
			box-shadow: 0 0 6px 6px rgba(0, 0, 0, 0.1);
			.me-header-vip-1 {
				padding: 0 16rpx;
				color: #333;
				font-weight: bold;
			}
			.me-header-vip-text {
				font-size: 28rpx;
				color: #333;
			}
		}
	}
</style>
